package com.cqyc.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.comm.Pager;
import com.cqyc.shop.comm.commException;
import com.cqyc.shop.domain.Shop;
import com.cqyc.shop.services.ShopServices;

@WebServlet(urlPatterns="/index.do")
public class ShopListServlet extends HttpServlet{
	private static final long serialVersionUID = -4853200002465428535L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private ShopServices shopServices = new ShopServices();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("执行从数据库读取操作");
		
		try {
			Shop shop = new Shop();
			
			//生鲜食品
			Pager pager_sxsp = new Pager();
			pager_sxsp.setPageSize(5);
			pager_sxsp.setCurrentPage(1);
			shop.setShopname("生鲜");
			
			Pager pager2_sxsp = new Pager();
			pager2_sxsp.setCurrentPage(2);
			pager2_sxsp.setPageSize(8);
			shop.setShopname("生鲜");
			
			Pager pager3_sxsp = new Pager();
			pager3_sxsp.setCurrentPage(2);
			pager3_sxsp.setPageSize(13);
			shop.setShopname("生鲜");
			
			
			Pager  pager4_sxsp = new Pager();
			pager4_sxsp.setCurrentPage(2);
			pager4_sxsp.setPageSize(14);
			shop.setShopname("生鲜");
			
			List<Shop> shops_sxsp = shopServices.findPager(shop,pager_sxsp);
			List<Shop> shops2_sxsp = shopServices.findPager(shop, pager2_sxsp);
			List<Shop> shops3_sxsp = shopServices.findPager(shop, pager3_sxsp);
			List<Shop>  shops4_sxsp = shopServices.findPager(shop, pager4_sxsp);
			request.setAttribute("shops_sxsp",shops_sxsp);
			
			request.setAttribute("shops2_sxsp", shops2_sxsp);
			
			request.setAttribute("shops3_sxsp", shops3_sxsp);
			
			request.setAttribute("shops4_sxsp", shops4_sxsp);
			
			
			//粮油副食
			Pager pager_lyfs = new Pager();
			pager_lyfs.setPageSize(5);
			pager_lyfs.setCurrentPage(1);
			shop.setShopname("粮油");
			
			Pager pager2_lyfs = new Pager();
			pager2_lyfs.setCurrentPage(2);
			pager2_lyfs.setPageSize(8);
			shop.setShopname("粮油");
			
			Pager pager3_lyfs = new Pager();
			pager3_lyfs.setCurrentPage(2);
			pager3_lyfs.setPageSize(13);
			shop.setShopname("粮油");
			
			
			Pager  pager4_lyfs = new Pager();
			pager4_lyfs.setCurrentPage(2);
			pager4_lyfs.setPageSize(14);
			shop.setShopname("粮油");
			
			List<Shop> shops_lyfs = shopServices.findPager(shop,pager_lyfs);
			List<Shop> shops2_lyfs = shopServices.findPager(shop, pager2_lyfs);
			List<Shop> shops3_lyfs = shopServices.findPager(shop, pager3_lyfs);
			List<Shop>  shops4_lyfs = shopServices.findPager(shop, pager4_lyfs);
			request.setAttribute("shops_lyfs",shops_lyfs);
			
			request.setAttribute("shops2_lyfs", shops2_lyfs);
			
			request.setAttribute("shops3_lyfs", shops3_lyfs);
			
			request.setAttribute("shops4_lyfs", shops4_lyfs);
			
			
			//肉类海鲜
			Pager pager_rlhx = new Pager();
			pager_rlhx.setPageSize(5);
			pager_rlhx.setCurrentPage(1);
			shop.setShopname("肉类");
			
			Pager pager2_rlhx = new Pager();
			pager2_rlhx.setCurrentPage(2);
			pager2_rlhx.setPageSize(8);
			shop.setShopname("肉类");
			
			Pager pager3_rlhx = new Pager();
			pager3_rlhx.setCurrentPage(2);
			pager3_rlhx.setPageSize(13);
			shop.setShopname("肉类");
			
			
			Pager  pager4_rlhx = new Pager();
			pager4_rlhx.setCurrentPage(2);
			pager4_rlhx.setPageSize(14);
			shop.setShopname("肉类");
			
			List<Shop> shops_rlhx = shopServices.findPager(shop,pager_rlhx);
			List<Shop> shops2_rlhx = shopServices.findPager(shop, pager2_rlhx);
			List<Shop> shops3_rlhx = shopServices.findPager(shop, pager3_rlhx);
			List<Shop>  shops4_rlhx = shopServices.findPager(shop, pager4_rlhx);
			request.setAttribute("shops_rlhx",shops_rlhx);
			
			request.setAttribute("shops2_rlhx", shops2_rlhx);
			
			request.setAttribute("shops3_rlhx", shops3_rlhx);
			
			request.setAttribute("shops4_rlhx", shops4_rlhx);
			
			
			//休闲食品
			Pager pager_xxsp = new Pager();
			pager_xxsp.setPageSize(5);
			pager_xxsp.setCurrentPage(1);
			shop.setShopname("休闲食品");
			
			Pager pager2_xxsp = new Pager();
			pager2_xxsp.setCurrentPage(2);
			pager2_xxsp.setPageSize(8);
			shop.setShopname("休闲食品");
			
			Pager pager3_xxsp = new Pager();
			pager3_xxsp.setCurrentPage(2);
			pager3_xxsp.setPageSize(13);
			shop.setShopname("休闲食品");
			
			
			Pager  pager4_xxsp = new Pager();
			pager4_xxsp.setCurrentPage(2);
			pager4_xxsp.setPageSize(14);
			shop.setShopname("休闲食品");
			
			List<Shop> shops_xxsp = shopServices.findPager(shop,pager_xxsp);
			List<Shop> shops2_xxsp = shopServices.findPager(shop, pager2_xxsp);
			List<Shop> shops3_xxsp = shopServices.findPager(shop, pager3_xxsp);
			List<Shop>  shops4_xxsp = shopServices.findPager(shop, pager4_xxsp);
			request.setAttribute("shops_xxsp",shops_xxsp);
			
			request.setAttribute("shops2_xxsp", shops2_xxsp);
			
			request.setAttribute("shops3_xxsp", shops3_xxsp);
			
			request.setAttribute("shops4_xxsp", shops4_xxsp);
			
			//调味饮品
			Pager pager_twcy = new Pager();
			pager_twcy.setPageSize(5);
			pager_twcy.setCurrentPage(1);
			shop.setShopname("茶饮");
			
			Pager pager2_twcy = new Pager();
			pager2_twcy.setCurrentPage(2);
			pager2_twcy.setPageSize(8);
			shop.setShopname("茶饮");
			
			Pager pager3_twcy = new Pager();
			pager3_twcy.setCurrentPage(2);
			pager3_twcy.setPageSize(13);
			shop.setShopname("茶饮");
			
			
			Pager  pager4_twcy = new Pager();
			pager4_twcy.setCurrentPage(2);
			pager4_twcy.setPageSize(14);
			shop.setShopname("茶饮");
			
			List<Shop> shops_twcy = shopServices.findPager(shop,pager_twcy);
			List<Shop> shops2_twcy = shopServices.findPager(shop, pager2_twcy);
			List<Shop> shops3_twcy = shopServices.findPager(shop, pager3_twcy);
			List<Shop>  shops4_twcy = shopServices.findPager(shop, pager4_twcy);
			request.setAttribute("shops_twcy",shops_twcy);
			
			request.setAttribute("shops2_twcy", shops2_twcy);
			
			request.setAttribute("shops3_twcy", shops3_twcy);
			
			request.setAttribute("shops4_twcy", shops4_twcy);
			
			//营养养生
			Pager pager_yyys = new Pager();
			pager_yyys.setPageSize(5);
			pager_yyys.setCurrentPage(1);
			shop.setShopname("养生");
			
			Pager pager2_yyys = new Pager();
			pager2_yyys.setCurrentPage(2);
			pager2_yyys.setPageSize(8);
			shop.setShopname("养生");
			
			Pager pager3_yyys = new Pager();
			pager3_yyys.setCurrentPage(2);
			pager3_yyys.setPageSize(13);
			shop.setShopname("养生");
			
			
			Pager  pager4_yyys = new Pager();
			pager4_yyys.setCurrentPage(2);
			pager4_yyys.setPageSize(14);
			shop.setShopname("养生");
			
			List<Shop> shops_yyys = shopServices.findPager(shop,pager_yyys);
			List<Shop> shops2_yyys = shopServices.findPager(shop, pager2_yyys);
			List<Shop> shops3_yyys = shopServices.findPager(shop, pager3_yyys);
			List<Shop>  shops4_yyys = shopServices.findPager(shop, pager4_yyys);
			request.setAttribute("shops_yyys",shops_yyys);
			
			request.setAttribute("shops2_yyys", shops2_yyys);
			
			request.setAttribute("shops3_yyys", shops3_yyys);
			
			request.setAttribute("shops4_yyys", shops4_yyys);
			
			
			logger.debug("查询数据成功");
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		} catch (Exception e) {
			throw new commException("list查找出现异常");
		}
	
	}
	
}
